package com.jit.app;

import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

import com.jit.app.service.DownloadBinder;
import com.jit.app.service.DownloadService;

public class AppMarketApplication extends Application {


    Intent intent;
    ServiceConnection serviceConnection;
    public static DownloadBinder downloadBinder;

    @Override
    public void onCreate() {
        super.onCreate();
        //绑定负责下载的Service
        intent = new Intent(this, DownloadService.class);
        this.startService(intent);
        serviceConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                downloadBinder = (DownloadBinder) service;
            }
            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        this.bindService(intent,serviceConnection, Context.BIND_AUTO_CREATE);

    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        this.unbindService(serviceConnection);
        this.stopService(intent);
    }
}
